<?php

/**
 * @desc Default action for logged user. Really is also a controller which 
 * delegates request handling to the backend manager.
 *
 */
class Backend_Action_Default extends Kernel_Controller_Abstract 
{

    /**
     * Метод обработки пользовательского запроса.
     *
     */
    public function process() 
    {
        if (Application::getMode() instanceof Kernel_Mode_Html) {
            Application::getResponse()->setFrameTemplate('backend/_frame/authorized.tpl');
        }

        // start filter structure manually
        parent::_forward(new Backend_Filter_Structure);

        // here search and execution of the appropriate module take place 
        // according to the current url
        parent::process();
        
        // these params have to pass through all the links of the backend
        Application::getResponse()->assign('through_default', 
            implode(',', Backend_Filter_Structure::params()));
    }

    /**
     * Возвращает описание компонента, который обработает запрошенное
     * действие, полученное из запроса.
     *
     * @return  Kernel_Token
     */
    protected function _getFilter() 
    {
        $module_name = Backend_Filter_Structure::get('module');

        $module = Kernel_Module::factory($module_name);

        $manager_name = Backend_Filter_Structure::get('manager');

        if (!is_object($manager = $module->getManager($manager_name))) {
            $this->_abort('Manager "' . $module_name . '::' . $manager_name . '" not found');
        }

        return $manager;
    }
    
}
